package com.cyan.app.workflow.util;

import android.app.Activity;
import android.app.Application;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by DXW on 2016/2/28.
 */
public class SysApplication extends Application {
    private List<Activity> mList = new LinkedList<Activity>();
    private static SysApplication instance;

    private SysApplication() {
    }

    public synchronized static SysApplication getInstance() {
        if (null == instance) {
            instance = new SysApplication();
        }
        return instance;
    }

    // add Activity
    public void addActivity(Activity activity) {
        mList.add(activity);
    }

    public void removeActivity(Activity activity) {
        mList.remove(activity);
        System.gc();
    }

    public void exit() {
       /* try {
            MyPreference.getInstance(this).storeBLotID(0);

            for (Activity activity : mList) {
                if (activity != null)
                    activity.finish();
            }

        } catch (Exception e) {
            // e.printStackTrace();
        } finally {
            System.exit(0);
            EventManager.getInstance().clearHandlers();
        }*/
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        System.gc();
    }
}